
/*
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is eden: ECMAScript data exchange notation. 
  
  The Initial Developer of the Original Code is
  Zwetan Kjukov <zwetan@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s):
*/

var self = this;

if( !self.buRRRn )
    {
    self.buRRRn = {};
    }

if( !buRRRn.eden  )
    {
    /* Singleton: buRRRn.eden
       The eden application.
    */
    buRRRn.eden = {};
    }

/* Property: version
   Contains eden version.
*/
buRRRn.eden.version = "0.1.0." + parseInt( "$Rev: 69 $".split( " " )[1] );

buRRRn.eden.prettyIndent   = 0;
buRRRn.eden.prettyPrinting = false;
buRRRn.eden.indentor       = "    ";
buRRRn.eden.newLine        = "\n";

buRRRn.eden.serialize = function( value/***/ )/*String*/
    {
    if( value === undefined )
        {
        return "undefined";
        }
    
    if( value === null )
        {
        return "null";
        }
    
    var Serializer = buRRRn.eden.Serializer;
    
    if( (value === self) || (value === _global) )
        {
        return Serializer.emitGlobal( value );
        }
    
    if( value["toSource"] != undefined )
        {
        /* note:
           We don't want to allow native toSource.
        */
        if( value.toSource.toString().indexOf( "native code" ) == -1 )
            {
            return value.toSource( this.prettyIndent );
            }
        }
    
    if( (typeof value == "string") || (value instanceof String) )
        {
        return Serializer.emitString( value );
        }
    
    if( (typeof value == "boolean") || (value instanceof Boolean) )
        {
        return (value == true) ? "true": "false";
        }
    
    if( (typeof value == "number") || (value instanceof Number) )
        {
        return value.toString();
        }
    
    if( value instanceof Date )
        {
        return Serializer.emitDate( value );
        }
    
    if( value instanceof Array )
        {
        return Serializer.emitArray( value );
        }
    
    if( value instanceof Function )
        {
        /* note:
           Should returns a string representing the source
           code of the function, but instead the choice
           has been made to only return the string
           "(function)".
           
           This choice is motivated by the fact that even
           if a function is a type it's not a data structure
           but more a code block and we are interested only
           in serialization of data structures.
        */
        return "(function)";
        }
    
    if( value instanceof Object )
        {
        return Serializer.emitObject( value );
        }            
    
    return "<unknown>";
    }

